package com.glela.common.aspect;

import java.util.HashMap;
import java.util.Map;

import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.response.ResponseBaseModel;

/**
 * api Controller层切面
 * 
 * @author liujie
 */
//@Aspect
//@Component
//@Order(1)
public class ApiControllerAspect
{
    public static Map<String, Long> illegalIpMap = new HashMap<String, Long>();

	static protected final Logger logger = LoggerFactory.getLogger(ApiControllerAspect.class);
  
// 	@Around("execution(* com.glela.controller.*.*(..))")
	public Object around(ProceedingJoinPoint pjp)
	{
  		return handleCause(pjp);
	}

	private Object handleCause(ProceedingJoinPoint pjp)
	{
		try {
 			return pjp.proceed();
		}
		catch (Throwable e) {
			 logger.error(e.getMessage(),e);
			 /*if(e instanceof BusinessException){
				return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
 			 }*/
			 return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
 		}
 	}
 }
